iT邦幫忙

第 12 屆 iThome 鐵人賽

DAY 4
0
自我挑戰組

開源軟體介簡及架設系列 第 4

[開源] OCS Inventory 資產管理系統(一)

  • 分享至 

  • xImage
  •  

如果要求的功能不多只想要收集電腦上的資訊的話,可以使用這一套開源的資產管理系統來收集每台電腦上的資訊,但是還是需使用 Agent 安裝每台電腦上面,如果您有建置網域服務的話可以例用網域服務方式來派送安裝,以後會再教怎麼來使用。

運行環境


  • 系統環境: CentOS 8
  • Web 服務: Apache 2.4.37
  • PHP 服務: PHP 7.4
  • 資料庫服務: MariaDB 10.3.17

由於 OCS Inventory 只能在 Apache 服務上運行不能在 Nginx ,由於有些服務在 Nginx 上是無法運行只能在 Apache 上才能運行。

安裝 Apache 服務


  • 先安裝 Apache 服務
dnf install httpd -y
  • 安裝完之後啟用 Apache 服務
systemctl enable httpd ; systemctl start httpd

安裝 MariaDB 服務


  • 安裝 MariaDB 服務
dnf install mariadb mariadb-server -y
  • 啟用 MariaDB 服務
systemctl restart mariadb ; systemctl enable mariadb
  • 資料庫基本設定
mysql_secure_installation   # 設定資料庫的root密碼

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): 第一次設定,直接按 Enter 鍵即可
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] 按 Y 設定資料庫 root 密碼
New password: 輸入新密碼
Re-enter new password: 再次輸入新密碼
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] 按 Y 移除anonymous users
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] 按 Y 關閉 root 遠端登入
 ... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] 按 Y 移除資料表 test
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] 按 Y 重新載入資料表權限
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

啟用 PowerTools 儲存庫


  • 啟用 PowerTools 存儲庫,該存儲庫提供了大多數 devel 套件
dnf install dnf-utils -y
dnf config-manager --set-enabled PowerTools

安裝 PHP 服務


CentOS 8 預設版本是 PHP 7.2 版,那如果想要使用比較新的版本的話需要新增加來源庫安裝

  • 安裝 epel-release 套件服務
dnf install -y epel-release
  • 安裝官方所提供來源庫版本
dnf install https://rpms.remirepo.net/enterprise/remi-release-8.rpm -y
  • 查詢目前可安裝的版本
dnf module list php
  • 使用 PHP 7.4 版本
dnf module reset php
dnf module enable php:remi-7.4
  • 安裝 PHP 套件
dnf install -y php php-mysqlnd php-pdo php-xml php-pear php-devel php-mbstring re2c gcc-c++ gcc \
php-fpm php-mysql php-gd php-cli php-json php-opcache php-curl php-ldap php-odbc php-xmlrpc php-soap \
curl curl-devel php-intl php-zip php-common php-domxml php-imap php-pear-CAS php-pecl-apcu \
php-pecl-zip
  • 安裝好 PHP 要去修改 vim /etc/php.ini 設定檔
修改前
;cgi.fix_pathinfo=1
修改後
cgi.fix_pathinfo=0

修改時區
[Date]
修改前
;date.timezone = 
修改後
date.timezone = Asia/Taipei

; 記憶體用量上限
memory_limit = 512M
; Script執行時間上限(單位:秒)
max_execution_time = 600
; Script處理資料時間上限(單位:秒)
max_input_time = 600
; Socket無回應斷線時間(單位:秒)
default_socket_timeout = 600

存檔
:wq

安裝 Perl 套件


dnf install -y perl-Archive-Zip perl-Compress-Zlib perl-DBD-MySQL perl-DBI perl-Mojolicious perl-Net-IP \
perl-Plack perl-SOAP-Lite perl-Switch perl-XML-Entities perl-XML-Simple

設定 OCS 資料庫


  • 建立 OCS 資料庫
mysql -u root -p

create database ocsweb CHARACTER SET utf8 COLLATE utf8_unicode_ci; 
CREATE USER 'ocs'@'localhost' IDENTIFIED BY 'New-Password';
GRANT ALL PRIVILEGES ON ocsweb.* TO 'ocs'@'localhost' IDENTIFIED BY 'New-Password';
FLUSH PRIVILEGES;

安裝 OCS Inventory Server 服務


  • 由於此安裝的版本是屬於 2.7 版,由於安裝包的預設路徑不清楚在那裡,因此會再從官方的 GitHub 重新下載新的安裝包再將路徑指向正確的。

  • 下載 OCS Inventory 官方的套件來源

dnf -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
dnf -y install  https://rpms.remirepo.net/enterprise/remi-release-8.rpm
  • 用 yum 來安裝 repo
dnf -y install https://rpm.ocsinventory-ng.org/ocsinventory-release-latest.el8.ocs.noarch.rpm
  • 安裝 OCS 服務
dnf install ocsinventory-server

版本更新升級


  • 上方安裝版本有很多沒有設定但也幫我安裝必需要的套件,所以會建議再重新安裝一次 OCS 服務,首先到 官方的 GitHub 查看是否有新版可以下載使用當下版本是 2.7,以照當時所下載新版為主。
wget https://github.com/OCSInventory-NG/OCSInventory-ocsreports/releases/download/2.7/OCSNG_UNIX_SERVER_2.7.tar.gz
  • 安裝新的版本
    解壓剛剛下載的版本
tar -xvzf OCSNG_UNIX_SERVER_2.7.tar.gz

cd OCSNG_UNIX_SERVER_2.7

./setup.sh
  • 執行後只要一直照著預設值不動,只有一個地方要注意選擇性改不改的路徑
+----------------------------------------------------------+
|                                                          |
|  Welcome to OCS Inventory NG Management server setup !   |
|                                                          |
+----------------------------------------------------------+

Trying to determine which OS or Linux distribution you use
+----------------------------------------------------------+
| Checking for Apache web server binaries !                |
+----------------------------------------------------------+

CAUTION: If upgrading Communication server from OCS Inventory NG 1.0 RC2 and
previous, please remove any Apache configuration for Communication Server!

Do you wish to continue ([y]/n)?
Assuming Communication server 1.0 RC2 or previous is not installed
on this computer.

Starting OCS Inventory NG Management server setup from folder /root/OCSNG_UNIX_SERVER_2.6
Storing log in file /root/OCSNG_UNIX_SERVER_2.6/ocs_server_setup.log

+----------------------------------------------------------+
| Checking for database server properties...               |
+----------------------------------------------------------+

Your MySQL client seems to be part of MySQL version 10.3.
Your computer seems to be running MySQL 4.1 or higher, good ;-)

Which host is running database server [localhost] ?
OK, database server is running on host localhost ;-)

On which port is running database server [3306] ?
OK, database server is running on port 3306 ;-)


+----------------------------------------------------------+
| Checking for Apache web server daemon...                 |
+----------------------------------------------------------+

Where is Apache daemon binary [/usr/sbin/httpd] ?
OK, using Apache daemon /usr/sbin/httpd ;-)


+----------------------------------------------------------+
| Checking for Apache main configuration file...           |
+----------------------------------------------------------+

Where is Apache main configuration file [/etc/httpd/conf/httpd.conf] ?
OK, using Apache main configuration file /etc/httpd/conf/httpd.conf ;-)


+----------------------------------------------------------+
| Checking for Apache user account...                      |
+----------------------------------------------------------+

Which user account is running Apache web server [apache] ?
OK, Apache is running under user account apache ;-)


+----------------------------------------------------------+
| Checking for Apache group...                             |
+----------------------------------------------------------+

Which user group is running Apache web server [apache] ?
OK, Apache is running under users group apache ;-)


+----------------------------------------------------------+
| Checking for Apache Include configuration directory...   |
+----------------------------------------------------------+

Setup found Apache Include configuration directory in
/etc/httpd/conf.d.
Setup will put OCS Inventory NG Apache configuration in this directory.
Where is Apache Include configuration directory [/etc/httpd/conf.d] ?
OK, Apache Include configuration directory /etc/httpd/conf.d found ;-)


+----------------------------------------------------------+
| Checking for PERL Interpreter...                         |
+----------------------------------------------------------+

Found PERL interpreter at </usr/bin/perl> ;-)
Where is PERL interpreter binary [/usr/bin/perl] ?
OK, Apache Include configuration directory /etc/httpd/conf.d found ;-)


+----------------------------------------------------------+
| Checking for PERL Interpreter...                         |
+----------------------------------------------------------+

Found PERL interpreter at </usr/bin/perl> ;-)
Where is PERL interpreter binary [/usr/bin/perl] ?
OK, using PERL interpreter /usr/bin/perl ;-)


Do you wish to setup Communication server on this computer ([y]/n)?


+----------------------------------------------------------+
|             Checking for Make utility...                 |
+----------------------------------------------------------+

OK, Make utility found at </usr/bin/make> ;-)

+----------------------------------------------------------+
|        Checking for Apache mod_perl version...           |
+----------------------------------------------------------+

Checking for Apache mod_perl version 1.99_22 or higher
Found that mod_perl version 1.99_22 or higher is available.
OK, Apache is using mod_perl version 1.99_22 or higher ;-)

+----------------------------------------------------------+
|    Checking for Communication server log directory...    |
+----------------------------------------------------------+

Communication server can create detailed logs. This logs can be enabled
by setting integer value of LOGLEVEL to 1 in Administration console
menu Configuration.
Where to put Communication server log directory [/var/log/ocsinventory-server] ?
OK, Communication server will put logs into directory /var/log/ocsinventory-server ;-)

+----------------------------------------------------------------------------+
|    Checking for Communication server plugins configuration directory...    |
+----------------------------------------------------------------------------+

Communication server need a directory for plugins configuration files.
Where to put Communication server plugins configuration files [/etc/ocsinventory-server/plugins] ?
OK, Communication server will put plugins configuration files into directory /etc/ocsinventory-server/plugins ;-)

+-------------------------------------------------------------------+
|   Checking for Communication server plugins perl directory...     |
+-------------------------------------------------------------------+

Communication server need a directory for plugins Perl modules files.
Where to put Communication server plugins Perl modules files [/etc/ocsinventory-server/perl] ?
OK, Communication server will put plugins Perl modules files into directory /etc/ocsinventory-server/perl ;-)


+----------------------------------------------------------+
| Checking for required Perl Modules...                    |
+----------------------------------------------------------+

Checking for DBI PERL module...
Found that PERL module DBI is available.
Checking for Apache::DBI PERL module...
Found that PERL module Apache::DBI is available.
Checking for DBD::mysql PERL module...
Found that PERL module DBD::mysql is available.
Checking for Compress::Zlib PERL module...
Found that PERL module Compress::Zlib is available.
Checking for XML::Simple PERL module...
Found that PERL module XML::Simple is available.
Checking for Net::IP PERL module...
Found that PERL module Net::IP is available.
Checking for SOAP::Lite Perl module...
Found that PERL module SOAP::Lite is available.
Checking for Archive::Zip Perl module...
Found that PERL module Archive::Zip is available.

+----------------------------------------------------------+
|         Checking for optional Perl Modules...            |
+----------------------------------------------------------+

Checking for Apache2::SOAP PERL module...
Found that PERL module SOAP::Apache2 is available.
Checking for XML::Entities PERL module...
Found that PERL module XML::Entities is available.


Do you wish to setup Rest API server on this computer ([y]/n)?

+----------------------------------------------------------+
| Checking for REST API Dependencies ...                   |
+----------------------------------------------------------+

Found that PERL module Mojolicious::Lite is available.
Found that PERL module Switch is available.
Found that PERL module Plack::Handler is available.

+----------------------------------------------------------+
| Configuring REST API Server files ...                    |
+----------------------------------------------------------+

Where do you want the API code to be store [/usr/lib64/perl5/vendor_perl] ?
Copying files to /usr/lib64/perl5/vendor_perl

+----------------------------------------------------------+
| Configuring REST API Server configuration files ...      |
+----------------------------------------------------------+


+----------------------------------------------------------+
|                 OK, looks good ;-)                       |
|                                                          |
|     Configuring Communication server Perl modules...     |
+----------------------------------------------------------+

Checking if your kit is complete...
Looks good
Writing Makefile for Apache::Ocsinventory
Writing MYMETA.yml and MYMETA.json

+----------------------------------------------------------+
|                 OK, looks good ;-)                       |
|                                                          |
|      Preparing Communication server Perl modules...      |
+----------------------------------------------------------+


+----------------------------------------------------------+
|                 OK, prepare finshed ;-)                  |
|                                                          |
|     Installing Communication server Perl modules...      |
+----------------------------------------------------------+


+----------------------------------------------------------+
| OK, Communication server Perl modules install finished;-)|
|                                                          |
|     Creating Communication server log directory...       |
+----------------------------------------------------------+

Creating Communication server log directory /var/log/ocsinventory-server.

Fixing Communication server log directory files permissions.
Configuring logrotate for Communication server.
Removing old communication server logrotate file /etc/logrotate.d/ocsinventory-NG
Writing communication server logrotate to file /etc/logrotate.d/ocsinventory-server


+----------------------------------------------------------------------+
|        OK, Communication server log directory created ;-)            |
|                                                                      |
|   Creating Communication server plugins configuration directory...   |
+----------------------------------------------------------------------+

Creating Communication server plugins configuration directory /etc/ocsinventory-server/plugins.


+----------------------------------------------------------------------+
| OK, Communication server plugins configuration directory created ;-) |
|                                                                      |
|        Creating Communication server plugins Perl directory...       |
+----------------------------------------------------------------------+

Creating Communication server plugins Perl directory /etc/ocsinventory-server/perl.


+----------------------------------------------------------------------+
|     OK, Communication server plugins Perl directory created ;-)      |
|                                                                      |
|               Now configuring Apache web server...                   |
+----------------------------------------------------------------------+

To ensure Apache loads mod_perl before OCS Inventory NG Communication Server,
Setup can name Communication Server Apache configuration file
'z-ocsinventory-server.conf' instead of 'ocsinventory-server.conf'.
Do you allow Setup renaming Communication Server Apache configuration file
to 'z-ocsinventory-server.conf' ([y]/n) ?
OK, using 'z-ocsinventory-server.conf' as Communication Server Apache configuration file
Removing old communication server configuration to file /etc/httpd/conf.d/ocsinventory.conf
Writing communication server configuration to file /etc/httpd/conf.d/z-ocsinventory-server.conf

+----------------------------------------------------------------------+
|       OK, Communication server setup successfully finished ;-)       |
|                                                                      |
| Please, review /etc/httpd/conf.d/z-ocsinventory-server.conf          |
|         to ensure all is good. Then restart Apache daemon.           |
+----------------------------------------------------------------------+


Do you wish to setup Administration Server (Web Administration Console)
on this computer ([y]/n)?

+----------------------------------------------------------+
|    Checking for Administration Server directories...     |
+----------------------------------------------------------+

CAUTION: Setup now install files in accordance with Filesystem Hierarchy
Standard. So, no file is installed under Apache root document directory
(Refer to Apache configuration files to locate it).
If you're upgrading from OCS Inventory NG Server 1.01 and previous, YOU
MUST REMOVE (or move) directories 'ocsreports' and 'download' from Apache
root document directory.
If you choose to move directory, YOU MUST MOVE 'download' directory to
Administration Server writable/cache directory (by default
/var/lib/ocsinventory-reports), especially if you use deployment feature.

Do you wish to continue ([y]/n)?
Assuming directories 'ocsreports' and 'download' removed from
Apache root document directory.

Where to copy Administration Server static files for PHP Web Console
[/usr/share/ocsinventory-reports] ? /var/www/html
OK, using directory /usr/share/ocsinventory-reports to install static files ;-)

Where to create writable/cache directories for deployment packages,
administration console logs, IPDiscover and SNMP [/var/lib/ocsinventory-reports] ?
OK, writable/cache directory is /var/lib/ocsinventory-reports ;-)


+----------------------------------------------------------+
|         Checking for required Perl Modules...            |
+----------------------------------------------------------+

Checking for DBI PERL module...
Found that PERL module DBI is available.
Checking for DBD::mysql PERL module...
Found that PERL module DBD::mysql is available.
Checking for XML::Simple PERL module...
Found that PERL module XML::Simple is available.
Checking for Net::IP PERL module...
Found that PERL module Net::IP is available.

+----------------------------------------------------------+
|      Installing files for Administration server...       |
+----------------------------------------------------------+

Creating PHP directory /usr/share/ocsinventory-reports/ocsreports.
Copying PHP files to /usr/share/ocsinventory-reports/ocsreports.
Fixing permissions on directory /usr/share/ocsinventory-reports/ocsreports.
Creating database configuration file /usr/share/ocsinventory-reports/ocsreports/dbconfig.inc.php.
Creating IPDiscover directory /var/lib/ocsinventory-reports/ipd.
Fixing permissions on directory /var/lib/ocsinventory-reports/ipd.
Creating packages directory /var/lib/ocsinventory-reports/download.
Fixing permissions on directory /var/lib/ocsinventory-reports/download.
Creating snmp mibs directory /var/lib/ocsinventory-reports/snmp.
Fixing permissions on directory /var/lib/ocsinventory-reports/snmp.
Creating Administration server log files directory /var/lib/ocsinventory-reports/logs.
Fixing permissions on directory /var/lib/ocsinventory-reports/logs.
Creating Administration server scripts log files directory /var/lib/ocsinventory-reports/scripts.
Fixing permissions on directory /var/lib/ocsinventory-reports/scripts.
Configuring IPDISCOVER-UTIL Perl script.
Installing IPDISCOVER-UTIL Perl script.
Fixing permissions on IPDISCOVER-UTIL Perl script.
Writing Administration server configuration to file /etc/httpd/conf.d/ocsinventory-reports.conf

+----------------------------------------------------------------------+
|        OK, Administration server installation finished ;-)           |
|                                                                      |
| Please, review /etc/httpd/conf.d/ocsinventory-reports.conf           |
|          to ensure all is good and restart Apache daemon.            |
|                                                                      |
| Then, point your browser to http://server//ocsreports                |
|        to configure database server and create/update schema.        |
+----------------------------------------------------------------------+


Setup has created a log file /root/OCSNG_UNIX_SERVER_2.6/ocs_server_setup.log. Please, save this file.
If you encounter error while running OCS Inventory NG Management server,
we can ask you to show us its content !

DON'T FORGET TO RESTART APACHE DAEMON !

Enjoy OCS Inventory NG ;-)
  • 可以修改路徑如下
預設路徑如下,必要修改到其他路徑這是給 web 服務用的,不然無法連線或者修改設定檔
Where to copy Administration Server static files for PHP Web Console
[/usr/share/ocsinventory-reports]?

這是修改後給予的路徑
Where to copy Administration Server static files for PHP Web Console
[/usr/share/ocsinventory-reports]?/var/www/html/

只要看到 Enjoy OCS Inventory NG ;-) 表示你已安裝成功了

設定後續的設定值


因版本更新有些權限可能會有異動過,所以需要手動修正回來

注意剛剛如果有修改路徑的話,後面的路徑要指向剛剛你所設定的路徑
chmod -R 766 /var/www/html/ocsreports

只給 apache 服務使用,路徑要注意如有修改記得要改
chown -R apache:apache /var/www/html/ocsreports
此路徑不用改,因為是預設
chown -R apache:apache /var/lib/ocsinventory-reports/

注意剛剛如果有修改路徑的話,後面的路徑要指向剛剛你所設定的路徑 
chcon -R -t httpd_sys_rw_content_t /var/www/html/ocsreports
備註:
httpd_sys_rw_content_t 要讓httpd寫入的目錄,例如上傳目錄

WEB 安裝畫面


MySQL login:輸入剛剛建立可以讓 ocs 登入的帳號

MySQL password:輸入剛剛建立可以讓 ocs 登入的密碼

Name of Database: 輸入剛剛建立的給 ocs 使用的資料庫名稱

MySQL HostName:輸入資料庫所在位置

ocs-5.png

正在安裝的畫面,安裝完之後按下 Click here to enter OCS-NG GUI

ocs-6.png

因資料庫版本有更新所以手動更新按下 Perform the update

ocs-7.png

更新完之後按下 Click here to enter OCS-NG GUI
ocs-8.png

登入畫面,官方預設帳號密碼都是 admin

ocs-9.png

登入之後會有一個警告訊息是說要請把 install.php 此檔移除或者修改名稱

ocs-10.png

OCS Inventory 記錄無法收集原因

BUBU 在測試的時候發現無法正常收到設備回報,去查了一下 OCS Log 檔,出現這樣子的錯誤,如果出現這樣子的錯誤表示 OCS 設定檔系統沒有協助設定好,這個意思是說 「 z-ocsinventory-server.conf 」設定檔裡的密碼是錯的,導至無法寫入資料庫要,要進到此設定檔裡面做修改就好了

ocs-error-1.png

vim /etc/httpd/conf.d/z-ocsinventory-server.conf

修改
PerlSetVar OCS_DB_PWD “New-Password”
  • 畫面如下

ocs-error-2.png

  • 然後再確認一下
vim /var/www/html/ocsreports/dbconfig.inc.php

注意此的密碼是不是沒有正確寫入為資料庫的密碼
define(“PSWD_BASE”,”New-Password”);

以上都確認好之後重啟服務,這樣子就可以正常收到資料了

systemctl restart httpd ; systemctl restart mariadb

參考相關網頁



上一篇
[開源] BookStack 知識庫管理結合第三方帳號(三)
下一篇
[開源] GLPI 資產管理系統(二)
系列文
開源軟體介簡及架設30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言